<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: LongTermController</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">LongTermController</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/app/controllers/long_term_controller_rb.html">
                app/controllers/long_term_controller.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="ApplicationController.html">
                ApplicationController
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000027">add_class</a>&nbsp;&nbsp;
      <a href="#M000029">auto_complete_for_course_number</a>&nbsp;&nbsp;
      <a href="#M000032">delete_shared_course</a>&nbsp;&nbsp;
      <a href="#M000024">index</a>&nbsp;&nbsp;
      <a href="#M000034">pop_semester</a>&nbsp;&nbsp;
      <a href="#M000033">push_semester</a>&nbsp;&nbsp;
      <a href="#M000026">remove</a>&nbsp;&nbsp;
      <a href="#M000025">show</a>&nbsp;&nbsp;
      <a href="#M000030">take_course_with_friend</a>&nbsp;&nbsp;
      <a href="#M000031">take_my_course_with_friend</a>&nbsp;&nbsp;
      <a href="#M000035">update_prerequisites</a>&nbsp;&nbsp;
      <a href="#M000028">update_semester</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000027" class="method-detail">
        <a name="M000027"></a>

        <div class="method-heading">
          <a href="#M000027" class="method-signature">
          <span class="method-name">add_class</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
add a class to course bin
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000027-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000027-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 40</span>
40:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_class</span>
41:     <span class="ruby-ivar">@user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
42:     <span class="ruby-identifier">class_id</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:course</span>][<span class="ruby-identifier">:number</span>]  
43:     <span class="ruby-identifier">class_id</span>.<span class="ruby-identifier">upcase!</span>
44:     (<span class="ruby-identifier">subject</span>, <span class="ruby-identifier">white</span>, <span class="ruby-identifier">number</span>) = <span class="ruby-identifier">class_id</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/^([A-Z]*)(\s*)(\d*)$/</span>)[<span class="ruby-value">0</span>]           
45:     
46:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">subject</span>.<span class="ruby-identifier">nil?</span> 
47:       <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:error</span>] = <span class="ruby-value str">&quot;Invalid Course&quot;</span>
48:       <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'ajax_flash'</span>
49:       <span class="ruby-keyword kw">return</span>
50:     <span class="ruby-keyword kw">else</span>
51:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">number</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">white</span>.<span class="ruby-identifier">empty?</span>
52:         <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:error</span>] = <span class="ruby-value str">&quot;Invalid Course&quot;</span>
53:         <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'ajax_flash'</span>
54:         <span class="ruby-keyword kw">return</span>
55:       <span class="ruby-keyword kw">else</span>
56:         <span class="ruby-identifier">results</span> = <span class="ruby-constant">CisSubject</span>.<span class="ruby-identifier">search_for_course</span>(<span class="ruby-identifier">class_id</span>)
57:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">results</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
58:           <span class="ruby-ivar">@course</span> = <span class="ruby-constant">CisCourse</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">results</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">id</span>
59:           <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">course_bin</span>.<span class="ruby-identifier">cis_courses</span>.<span class="ruby-identifier">concat</span> <span class="ruby-ivar">@course</span>
60:         <span class="ruby-keyword kw">else</span>
61:           <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:error</span>] = <span class="ruby-value str">&quot;Invalid Course&quot;</span>
62:           <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'ajax_flash'</span>
63:           <span class="ruby-keyword kw">return</span>
64:         <span class="ruby-keyword kw">end</span>
65:       <span class="ruby-keyword kw">end</span>
66:     <span class="ruby-keyword kw">end</span>
67:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000029" class="method-detail">
        <a name="M000029"></a>

        <div class="method-heading">
          <a href="#M000029" class="method-signature">
          <span class="method-name">auto_complete_for_course_number</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
autocomplete the course name
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000029-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 97</span>
 97:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">auto_complete_for_course_number</span>
 98:     <span class="ruby-identifier">flash</span>.<span class="ruby-identifier">keep</span>
 99:     <span class="ruby-ivar">@courses</span> = <span class="ruby-constant">CisSubject</span>.<span class="ruby-identifier">search_for_course</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:course</span>][<span class="ruby-identifier">:number</span>])
100:     <span class="ruby-identifier">render</span> <span class="ruby-identifier">:partial</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'auto_complete_course'</span>
101:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000032" class="method-detail">
        <a name="M000032"></a>

        <div class="method-heading">
          <a href="#M000032" class="method-signature">
          <span class="method-name">delete_shared_course</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
removes a shared course link only does so in one way (friend will still
share the course with you)
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000032-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 185</span>
185:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_shared_course</span>
186:     <span class="ruby-identifier">shared_course_id</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]
187:     
188:     <span class="ruby-constant">SharedCourse</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">shared_course_id</span>)
189:   
190:     <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">:back</span>
191:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000024" class="method-detail">
        <a name="M000024"></a>

        <div class="method-heading">
          <a href="#M000024" class="method-signature">
          <span class="method-name">index</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="LongTermController.html#M000025">show</a> the currently logged in
user&#8216;s long term view
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000024-source">
<pre>
   <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 3</span>
3:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">index</span>
4:     <span class="ruby-ivar">@user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
5:     <span class="ruby-ivar">@course_bin_courses</span> = <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">course_bin</span>.<span class="ruby-identifier">cis_courses</span>
6:     <span class="ruby-ivar">@semesters</span> = <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">:all</span>
7:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000034" class="method-detail">
        <a name="M000034"></a>

        <div class="method-heading">
          <a href="#M000034" class="method-signature">
          <span class="method-name">pop_semester</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
removes the last semester from the user&#8216;s schedule
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000034-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 211</span>
211:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pop_semester</span>
212:     <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'index'</span>
213:     
214:     <span class="ruby-identifier">current_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
215:     
216:     <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">empty?</span>
217:       <span class="ruby-identifier">last_semester</span> = <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">semesters</span>[<span class="ruby-value">-1</span>]
218:       <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">last_semester</span>
219:     <span class="ruby-keyword kw">end</span>
220:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000033" class="method-detail">
        <a name="M000033"></a>

        <div class="method-heading">
          <a href="#M000033" class="method-signature">
          <span class="method-name">push_semester</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
adds a semester to the user&#8216;s schedule at the end
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000033-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 194</span>
194:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">push_semester</span>
195:     <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'index'</span>
196:     
197:     <span class="ruby-identifier">current_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
198:     
199:     <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">empty?</span>
200:       <span class="ruby-identifier">last_semester</span> = <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">semesters</span>[<span class="ruby-value">-1</span>]
201:       <span class="ruby-identifier">start_sem</span>, <span class="ruby-identifier">start_year</span> = <span class="ruby-identifier">last_semester</span>.<span class="ruby-identifier">get_next_semester_and_year</span>
202:     <span class="ruby-keyword kw">else</span>
203:       <span class="ruby-identifier">start_sem</span> = <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">start_sem</span>
204:       <span class="ruby-identifier">start_year</span> = <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">start_year</span>
205:     <span class="ruby-keyword kw">end</span>
206:     
207:     <span class="ruby-constant">Semester</span>.<span class="ruby-identifier">create_semesters</span>(<span class="ruby-identifier">start_sem</span>, <span class="ruby-identifier">start_year</span>, <span class="ruby-value">1</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">semester</span><span class="ruby-operator">|</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">semesters</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">semester</span>}
208:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000026" class="method-detail">
        <a name="M000026"></a>

        <div class="method-heading">
          <a href="#M000026" class="method-signature">
          <span class="method-name">remove</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="LongTermController.html#M000026">remove</a> a course from semester
or course bin
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000026-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 22</span>
22:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove</span>
23:     <span class="ruby-identifier">user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
24:     <span class="ruby-ivar">@course_id</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:course_id</span>].<span class="ruby-identifier">to_i</span>
25:     <span class="ruby-ivar">@semester_id</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:semester_id</span>].<span class="ruby-identifier">to_i</span>
26:     <span class="ruby-identifier">course</span> = <span class="ruby-constant">CisCourse</span>.<span class="ruby-identifier">find</span>(<span class="ruby-ivar">@course_id</span>)
27:     
28:     
29:     <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@semester_id</span> <span class="ruby-operator">==</span> <span class="ruby-value">-1</span>
30:       <span class="ruby-identifier">user</span>.<span class="ruby-identifier">course_bin</span>.<span class="ruby-identifier">cis_courses</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">course</span>)
31:     <span class="ruby-keyword kw">else</span>
32:       <span class="ruby-identifier">semester</span> = <span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-ivar">@semester_id</span>)
33:       <span class="ruby-identifier">semester</span>.<span class="ruby-identifier">cis_courses</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">course</span>)
34:       <span class="ruby-comment cmt"># sections from semester plan</span>
35:       <span class="ruby-identifier">course</span>.<span class="ruby-identifier">sections_for_semester</span>(<span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-ivar">@semester_id</span>)) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">find</span>(<span class="ruby-ivar">@semester_id</span>).<span class="ruby-identifier">course_plan</span>.<span class="ruby-identifier">remove_cis_sections</span> <span class="ruby-identifier">course</span>.<span class="ruby-identifier">sections_for_semester</span>(<span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-ivar">@semester_id</span>))
36:     <span class="ruby-keyword kw">end</span>
37:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000025" class="method-detail">
        <a name="M000025"></a>

        <div class="method-heading">
          <a href="#M000025" class="method-signature">
          <span class="method-name">show</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="LongTermController.html#M000025">show</a> someone&#8216;s long
term view
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000025-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 10</span>
10:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">show</span>
11:     <span class="ruby-ivar">@user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]
12:     <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@user</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
13:       <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'index'</span>
14:       <span class="ruby-keyword kw">return</span>
15:     <span class="ruby-keyword kw">end</span>
16:     
17:     <span class="ruby-ivar">@course_bin_courses</span> = <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">course_bin</span>.<span class="ruby-identifier">cis_courses</span>
18:     <span class="ruby-ivar">@semesters</span> = <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">:all</span>
19:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000030" class="method-detail">
        <a name="M000030"></a>

        <div class="method-heading">
          <a href="#M000030" class="method-signature">
          <span class="method-name">take_course_with_friend</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
take a course with a friend called from either own view or friend&#8216;s
view display&#8216;s list of friends if initiated from own view
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000030-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000030-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 106</span>
106:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">take_course_with_friend</span>
107:     <span class="ruby-identifier">current_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
108:     <span class="ruby-identifier">course_id</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:course_id</span>].<span class="ruby-identifier">to_i</span>
109:     <span class="ruby-identifier">semester_id</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:semester_id</span>].<span class="ruby-identifier">to_i</span>
110:     <span class="ruby-identifier">friend_id</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:friend_id</span>].<span class="ruby-identifier">to_i</span>
111:     
112:     <span class="ruby-comment cmt">#if friend id isn't set, then we're in our own view</span>
113:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">friend_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
114:       <span class="ruby-comment cmt">#prompt for name in view</span>
115:       <span class="ruby-ivar">@course</span> = <span class="ruby-constant">CisCourse</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">course_id</span>
116:       <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">semester_id</span> <span class="ruby-operator">!=</span> <span class="ruby-value">-1</span>)
117:         <span class="ruby-ivar">@semester</span> = <span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">semester_id</span>
118:       <span class="ruby-keyword kw">else</span>
119:         <span class="ruby-ivar">@semester</span> = <span class="ruby-keyword kw">nil</span>
120:       <span class="ruby-keyword kw">end</span>
121:       <span class="ruby-ivar">@friends</span> = <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">friends</span>
122:     <span class="ruby-keyword kw">else</span>
123:       <span class="ruby-comment cmt">#we're in friends view</span>
124:       <span class="ruby-comment cmt">#redirect</span>
125:       <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">:back</span>      
126:       
127:       <span class="ruby-comment cmt">#add course to your schedule in same semester</span>
128:       
129:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">semester_id</span> <span class="ruby-operator">==</span> <span class="ruby-value">-1</span>
130:         <span class="ruby-comment cmt">#course bin</span>
131:         <span class="ruby-identifier">semester</span> = <span class="ruby-keyword kw">nil</span>
132:       <span class="ruby-keyword kw">else</span>
133:         <span class="ruby-identifier">orig_semester</span> = <span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">semester_id</span>
134:         
135:         <span class="ruby-identifier">semester</span> = <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">:first</span>, <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> {<span class="ruby-identifier">:year</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">orig_semester</span>.<span class="ruby-identifier">year</span>, <span class="ruby-identifier">:semester</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">orig_semester</span>.<span class="ruby-identifier">semester</span>}
136:       <span class="ruby-keyword kw">end</span>
137:       
138:       <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">has_course?</span> <span class="ruby-identifier">course_id</span>
139:         <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">semester</span>.<span class="ruby-identifier">nil?</span>
140:           <span class="ruby-identifier">semester</span>.<span class="ruby-identifier">cis_courses</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-constant">CisCourse</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">course_id</span>)
141:         <span class="ruby-keyword kw">else</span>
142:           <span class="ruby-comment cmt">#course bin if semester doesn't exists</span>
143:           <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">course_bin</span>.<span class="ruby-identifier">cis_courses</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-constant">CisCourse</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">course_id</span>)
144:         <span class="ruby-keyword kw">end</span>
145:       <span class="ruby-keyword kw">end</span>
146: 
147:       <span class="ruby-comment cmt">#create shared course object</span>
148:       <span class="ruby-identifier">create_and_link_shared_course</span> <span class="ruby-identifier">friend_id</span>, <span class="ruby-identifier">course_id</span>
149:     <span class="ruby-keyword kw">end</span>
150:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000031" class="method-detail">
        <a name="M000031"></a>

        <div class="method-heading">
          <a href="#M000031" class="method-signature">
          <span class="method-name">take_my_course_with_friend</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
second step of taking course with friend initiated from own view
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000031-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 153</span>
153:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">take_my_course_with_friend</span>
154:     <span class="ruby-comment cmt">#course id</span>
155:     <span class="ruby-identifier">course_id</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:course_id</span>].<span class="ruby-identifier">to_i</span>
156: 
157:     <span class="ruby-comment cmt">#get selected friends</span>
158:     <span class="ruby-identifier">selected_friends</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:friends</span>]
159:     
160:     <span class="ruby-comment cmt">#redirect</span>
161:     <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'index'</span>
162:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">selected_friends</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
163:       <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:error</span>] = <span class="ruby-value str">&quot;You must select a friend to take this course with.&quot;</span>
164:       <span class="ruby-keyword kw">return</span>
165:         <span class="ruby-keyword kw">end</span>
166:         <span class="ruby-identifier">selected_friends</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">friend_id</span><span class="ruby-operator">|</span>
167:           
168:           <span class="ruby-identifier">friend_id</span> = <span class="ruby-identifier">friend_id</span>.<span class="ruby-identifier">to_i</span>
169:           
170:           <span class="ruby-identifier">friend</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">friend_id</span>
171:           
172:           <span class="ruby-comment cmt">#check to see if friend already has course</span>
173:           <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">friend</span>.<span class="ruby-identifier">has_course?</span> <span class="ruby-identifier">course_id</span>
174:             <span class="ruby-comment cmt">#place in friend's course bin otherwise</span>
175:             <span class="ruby-identifier">friend</span>.<span class="ruby-identifier">course_bin</span>.<span class="ruby-identifier">cis_courses</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-constant">CisCourse</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">course_id</span>)
176:           <span class="ruby-keyword kw">end</span>
177:         
178:           <span class="ruby-comment cmt">#created shared course object</span>
179:           <span class="ruby-identifier">create_and_link_shared_course</span> <span class="ruby-identifier">friend_id</span>, <span class="ruby-identifier">course_id</span>
180:         <span class="ruby-keyword kw">end</span>
181:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000035" class="method-detail">
        <a name="M000035"></a>

        <div class="method-heading">
          <a href="#M000035" class="method-signature">
          <span class="method-name">update_prerequisites</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
checks for prerequisites and sends an RJS update back to the client
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000035-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 223</span>
223:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_prerequisites</span>
224:     <span class="ruby-ivar">@user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
225:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000028" class="method-detail">
        <a name="M000028"></a>

        <div class="method-heading">
          <a href="#M000028" class="method-signature">
          <span class="method-name">update_semester</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
move a class from one semester to another
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000028-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/long_term_controller.rb, line 70</span>
70:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_semester</span>
71:     <span class="ruby-ivar">@user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
72:     <span class="ruby-identifier">course</span> = <span class="ruby-constant">CisCourse</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>].<span class="ruby-identifier">split</span>(<span class="ruby-value str">'_'</span>)[<span class="ruby-value">2</span>].<span class="ruby-identifier">to_i</span>)
73:     <span class="ruby-identifier">new_semester_id</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:new_semester</span>].<span class="ruby-identifier">to_i</span>
74:     <span class="ruby-identifier">old_semester_id</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>].<span class="ruby-identifier">split</span>(<span class="ruby-value str">'_'</span>)[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>
75: 
76:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">old_semester_id</span> <span class="ruby-operator">==</span> <span class="ruby-value">-1</span>
77:       <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">course_bin</span>.<span class="ruby-identifier">cis_courses</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">course</span>)
78:     <span class="ruby-keyword kw">else</span>
79:       <span class="ruby-identifier">course</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">old_semester_id</span>))
80:       <span class="ruby-comment cmt"># remove sections from old semester</span>
81:       <span class="ruby-identifier">course</span>.<span class="ruby-identifier">sections_for_semester</span>(<span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">old_semester_id</span>)) <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">old_semester_id</span>).<span class="ruby-identifier">course_plan</span>.<span class="ruby-identifier">remove_cis_sections</span> <span class="ruby-identifier">course</span>.<span class="ruby-identifier">sections_for_semester</span>(<span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">old_semester_id</span>))
82:     <span class="ruby-keyword kw">end</span>
83:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_semester_id</span> <span class="ruby-operator">==</span> <span class="ruby-value">-1</span>
84:       <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">course_bin</span>.<span class="ruby-identifier">cis_courses</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">course</span>)
85:     <span class="ruby-keyword kw">else</span>
86:       <span class="ruby-identifier">course</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">new_semester_id</span>))
87:     <span class="ruby-keyword kw">end</span>
88: 
89:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_semester_id</span> <span class="ruby-operator">!=</span> <span class="ruby-value">-1</span>
90:       <span class="ruby-identifier">semester_obj</span> = <span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">new_semester_id</span>)
91:     <span class="ruby-keyword kw">end</span>
92: 
93:     <span class="ruby-identifier">render</span> <span class="ruby-identifier">:partial</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'course'</span>, <span class="ruby-identifier">:object</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">course</span>, <span class="ruby-identifier">:locals</span> =<span class="ruby-operator">&gt;</span> {<span class="ruby-identifier">:semester_obj</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">semester_obj</span> <span class="ruby-operator">||</span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:effect</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>}
94:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>